﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Telerik.Windows.Controls;
using System.Collections.Generic;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCF.UI.ChildWindows;
using Baosight.ZNH.ZMCF.UI.Utils;

namespace Baosight.ZNH.ZMCF.UI
{
    /// <summary>
    /// 业务联系单
    /// 发送联系单
    /// </summary>
    /// Title:ZMCC11
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 严洪浩
    /// Version: 1.0
    /// History:
    ///       2011-06-28  严洪浩 [创建]
    ///
    public partial class ZMCF30 : EFViewCmes
    {
        private Authority _block = new Authority();

        public ZMCF30()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(_block.AuthorityStatus(true));
            base.Initialize(initData);
        }

        /// <summary>
        /// 选中主表数据显示从表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void grid_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            if (null != this.grid.SelectedItem)
            {
                EIRow _row = (this.grid.SelectedItem as UIBaseEntity).GetEIRow();
                string fdStatus = _row["fdStatus"] == null ? "" : _row["fdStatus"].ToString();

                if ("已反馈".Equals(fdStatus))
                {
                    this.DETAILS.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    this.DETAILS.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            else
            {
                this.DETAILS.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        /// <summary>
        /// 列表中修改、删除前设置属性、参数
        /// 传递到后台代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 反馈操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnFeedbackButtonClick(object sender, RoutedEventArgs e)
        {
            IList<EIRow> _list = this.grid.GetCheckedEIRows() == null ? new List<EIRow>() : this.grid.GetCheckedEIRows();

            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            EIRow row = new EIRow();
            if (_list.Count > 0)
            {
                string fdStatus = _list[0]["fdStatus"].ToString();
                if ("已反馈".Equals(fdStatus))
                {
                    base.OpenEFWindowAlert("该记录已经反馈！", true);
                    return;
                }

                row = BaseTools.GetEIRowByOldEIRow(this.EIDataContext.GetBlock("result").GetColumns(), _list[0]);
            }
            eIBlock.SetRow(0, row);
            eiInfo.AddBlock(eIBlock);

            base.OnUpdateButtonClickPopup("批示反馈", eiInfo, "领导批示-反馈", "insert", null, sender, e);
        }

        /// <summary>
        /// 从表弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                //刷新从表Grid区域
                this.grid.Refresh();
            }

            //按钮生效
            base.TempButtonOpen(true);
        }


        /// <summary>
        /// 从表新增或修改之前的数据传输
        /// 构造新增页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        public override void OpenPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {
            LeaderAuthority _leaderAuthority = new LeaderAuthority(_dialogType);

            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cf.empName"));
            _leaderAuthority.EIDataContext = new Platform.Core.UI.EIDataContext();
            _leaderAuthority.EIDataContext.Update(_eIInfo);

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = _leaderAuthority;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(OpenWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }

    }
}
